#include "nbmask.h"

NBMask::NBMask(): radius(0) {}

NBMask::NBMask(int r, vector<Coordinate>& exs): radius(r)
{
		for (vector<Coordinate>::const_iterator i = exs.begin(); i != exs.end(); ++i)
			exceptions.push_back(*i);
}

NBMask::NBMask(int r): radius(r)
{}

NBMask::NBMask(const NBMask& other): radius(other.radius)
{
	for (vector<Coordinate>::const_iterator i = other.exceptions.begin(); i != other.exceptions.end(); ++i)
		exceptions.push_back(*i);
}

vector<Coordinate> NBMask::apply(const Coordinate& center) const
{
	vector<Coordinate> nb;
	bool cooIsException = false;
	for (int row = center.row - radius; row <= center.row + radius; row++)
		for (int col = center.col - radius; col <= center.col + radius; col++)
		{
			cooIsException = false;
			Coordinate candidateCoo(row,col);
			for (int i = 0; i < (int) exceptions.size() && !cooIsException; ++i)
				if (candidateCoo == exceptions[i])
					cooIsException = true;
			if (!cooIsException)
				nb.push_back(candidateCoo);
		}
	return nb;
}

NBMask& NBMask::operator= (const NBMask& other)
{
	if (this == &other)
		return *this;
	exceptions.clear();
	for (vector<Coordinate>::const_iterator i = other.exceptions.begin(); i != other.exceptions.end(); ++i)
		exceptions.push_back(*i);
	radius = other.radius;
	return *this;
}


ostream& operator<< (ostream& os, const NBMask& mask)
{
	if (mask.exceptions.size() == 0)
		os << "This NBMask object has radius = " << mask.radius << " and no masked neighbor.";
	else
	{
		os << "This NBMask object has radius = " << mask.radius << " with the following masked neighbors: ";
		for (vector<Coordinate>::const_iterator i = mask.exceptions.begin(); i != mask.exceptions.end(); ++i)
			os << *i << ", ";
		os << "\b";
	}
	return os;
}